<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="承运商编码" prop="carrierID">
        <el-input
          v-model="queryParams.carrierID"
          placeholder="请输入承运商编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['carriermangement:carriermangement:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['carriermangement:carriermangement:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['carriermangement:carriermangement:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['carriermangement:carriermangement:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="carriermangementList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <!--      <el-table-column label="编号" align="center" prop="id" />-->
      <el-table-column label="承运商编码" align="center" prop="carrierID"/>
      <el-table-column label="公司名称" align="center" prop="companyName"/>
      <el-table-column label="承运商类型" align="center" prop="carrierType"/>
      <el-table-column label="司机数量" align="center" prop="dNumber"/>
      <el-table-column label="车辆数量" align="center" prop="vNumber"/>
      <el-table-column label="公司地址" align="center" prop="compantAddress"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-xq"-->
<!--            @click="handlexq(scope.row)"-->
<!--            v-hasPermi="['carriermangement:carriermangement:xq']"-->
<!--          >详情-->
<!--          </el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['carriermangement:carriermangement:edit']"
          >修改
          </el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['carriermangement:carriermangement:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改承运商管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="承运商编码" prop="carrierID">
          <el-input v-model="form.carrierID" placeholder="请输入承运商编码"/>
        </el-form-item>
        <el-form-item label="公司名称" prop="companyName">
          <el-input v-model="form.companyName" placeholder="请输入公司名称"/>
        </el-form-item>
        <el-form-item label="营业执照号码" prop="businessLicenseNUmber">
          <el-input v-model="form.businessLicenseNUmber" placeholder="请输入营业执照号码"/>
        </el-form-item>
        <el-form-item label="税务登记号码" prop="taxRegistrationNumBer">
          <el-input v-model="form.taxRegistrationNumBer" placeholder="请输入税务登记号码"/>
        </el-form-item>
        <el-form-item label="法人代表" prop="legalRepresentative">
          <el-input v-model="form.legalRepresentative" placeholder="请输入法人代表"/>
        </el-form-item>
        <el-form-item label="公司地址" prop="compantAddress">
          <el-input v-model="form.compantAddress" placeholder="请输入公司地址"/>
        </el-form-item>
        <el-form-item label="邮编" prop="zipCode">
          <el-input v-model="form.zipCode" placeholder="请输入邮编"/>
        </el-form-item>
        <el-form-item label="营业执照" prop="businessLicense">
          <el-input v-model="form.businessLicense" placeholder="请输入营业执照"/>
        </el-form-item>
        <el-form-item label="备注信息" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入备注信息"/>
        </el-form-item>
        <el-form-item label="姓名" prop="contactName">
          <el-input v-model="form.contactName" placeholder="请输入姓名"/>
        </el-form-item>
        <el-form-item label="手机号码" prop="phoneNumber">
          <el-input v-model="form.phoneNumber" placeholder="请输入手机号码"/>
        </el-form-item>
        <el-form-item label="部门" prop="department">
          <el-input v-model="form.department" placeholder="请输入部门"/>
        </el-form-item>
        <el-form-item label="职位" prop="position">
          <el-input v-model="form.position" placeholder="请输入职位"/>
        </el-form-item>
        <el-form-item label="E-maile" prop="email">
          <el-input v-model="form.email" placeholder="请输入E-maile"/>
        </el-form-item>
        <el-form-item label="QQ" prop="qq">
          <el-input v-model="form.qq" placeholder="请输入QQ"/>
        </el-form-item>
        <el-form-item label="发票抬头" prop="invoiceTitle">
          <el-input v-model="form.invoiceTitle" placeholder="请输入发票抬头"/>
        </el-form-item>
        <el-form-item label="纳税人识别号" prop="taxpaterID">
          <el-input v-model="form.taxpaterID" placeholder="请输入纳税人识别号"/>
        </el-form-item>
        <el-form-item label="开户行" prop="bankName">
          <el-input v-model="form.bankName" placeholder="请输入开户行"/>
        </el-form-item>
        <el-form-item label="开户名称" prop="accuontName">
          <el-input v-model="form.accuontName" placeholder="请输入开户名称"/>
        </el-form-item>
        <el-form-item label="银行账号" prop="bankAccount">
          <el-input v-model="form.bankAccount" placeholder="请输入银行账号"/>
        </el-form-item>
        <el-form-item label="是否签订合同" prop="isContractSigned">
          <el-input v-model="form.isContractSigned" placeholder="请输入是否签订合同"/>
        </el-form-item>
        <el-form-item label="司机外键" prop="did">
          <el-input v-model="form.did" placeholder="请输入司机外键"/>
        </el-form-item>
        <el-form-item label="车辆外键" prop="vid">
          <el-input v-model="form.vid" placeholder="请输入车辆外键"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listCarriermangement,
  getCarriermangement,
  delCarriermangement,
  addCarriermangement,
  updateCarriermangement
} from "@/api/carriermangement/carriermangement";

export default {
  name: "Carriermangement",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 承运商管理表格数据
      carriermangementList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        carrierID: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handlexq(row) {
      // this.reset();
      // const id = row.id || this.ids
      // getCarriermangement(id).then(response => {
      //   this.form = response.data;
        // this.open = true;
        // this.title = "修改承运商管理";
      const id = row.id || this.ids
        this.$router.push({path: '/carriermanagementxq', query: {id: id}})
      },

    /** 查询承运商管理列表 */
    getList() {
      this.loading = true;
      listCarriermangement(this.queryParams).then(response => {
        this.carriermangementList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        carrierID: null,
        companyName: null,
        carrierType: null,
        businessLicenseNUmber: null,
        taxRegistrationNumBer: null,
        legalRepresentative: null,
        region: null,
        compantAddress: null,
        zipCode: null,
        carrierStatus: null,
        businessLicense: null,
        remarks: null,
        contactName: null,
        phoneNumber: null,
        department: null,
        position: null,
        email: null,
        qq: null,
        invoiceTitle: null,
        taxpaterID: null,
        bankName: null,
        accuontName: null,
        bankAccount: null,
        isContractSigned: null,
        did: null,
        vid: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      // this.open = true;
      // this.title = "添加承运商管理";
      this.$router.push({path: '/carriermanagementadd'})
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCarriermangement(id).then(response => {
        this.form = response.data;
        // this.open = true;
        // this.title = "修改承运商管理";
        this.$router.push({path: '/carriermanagementadd', query: {id: id}})
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCarriermangement(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCarriermangement(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除承运商管理编号为"' + ids + '"的数据项？').then(function () {
        return delCarriermangement(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('carriermangement/carriermangement/export', {
        ...this.queryParams
      }, `carriermangement_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
